/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package javaapplication3;

import gdr.maps.MapPaths;
import java.awt.Point;
import java.io.File;
import java.io.IOException;
import java.util.Timer;
import java.util.Vector;
import javax.swing.ImageIcon;


/**
 *
 * @author iamdelac
 */
public class RemotePlayer extends javax.swing.JLabel implements Runnable{

    protected final String STAND="/player/stand/";
    protected final String WALK="/player/walk/";
    protected final String ATTACK="/player/attack/";
    public String nome_player;
    private Vector <javax.swing.ImageIcon[]> sprites;
    protected String stato;
    private String orientation;
    protected RemotePlayer nemicoFocused;




/**
 * <pre>
 *@param posizione (left || right)
 *@param nome_fighter
 </pre>

 */
    public RemotePlayer (String nome_fighter) {
       super();
      
       sprites = new Vector();
       this.setDoubleBuffered(true);
       this.nome_player = nome_fighter;
       this.orientation = "n/";
       stato = STAND;
       cambiaAnimazione(STAND);
       }


public void cambiaAnimazione(String animazione){
            
             Vector <javax.swing.ImageIcon[]> sprites_temp = new Vector <javax.swing.ImageIcon[]>();
             for (File file : new File ( getClass().getResource(stato+orientation).getFile()).listFiles(new ImageFileFilter()) )
             {
              try {//carico in memoria tutte le immagini di un' azione per tutti gli orientamenti
                String[] path = file.getCanonicalPath().split("/");
                String nameFile = path[path.length-1];
                javax.swing.ImageIcon[] orientations = new javax.swing.ImageIcon[8];
                orientations[0] = new javax.swing.ImageIcon(getClass().getResource(stato+"n/"+nameFile));
                orientations[1] = new javax.swing.ImageIcon(getClass().getResource(stato+"ne/"+nameFile));
                orientations[2] = new javax.swing.ImageIcon(getClass().getResource(stato+"e/"+nameFile));
                orientations[3] = new javax.swing.ImageIcon(getClass().getResource(stato+"se/"+nameFile));
                orientations[4] = new javax.swing.ImageIcon(getClass().getResource(stato+"s/"+nameFile));
                orientations[5] = new javax.swing.ImageIcon(getClass().getResource(stato+"sw/"+nameFile));
                orientations[6] = new javax.swing.ImageIcon(getClass().getResource(stato+"w/"+nameFile));
                orientations[7] = new javax.swing.ImageIcon(getClass().getResource(stato+"nw/"+nameFile));
                sprites_temp.add(orientations);
                  }
               catch (IOException ex) {ex.printStackTrace();}
               sprites = sprites_temp;
             }
            setSize(sprites_temp.get(0)[0].getIconWidth(), sprites.get(0)[0].getIconHeight());

}







public void attacca (RemotePlayer nemico)
        {
         
        }

public void setStato(String stato){
	this.stato=stato;
}

public void setOrientation(String or)
	{
	 orientation=or;
	}
        



public  void run (){
    String statoOld = stato;
    ImageIcon[] sprite;
    boolean oneCycle = false;
while (true)
     {
      
      for( int h=0; h<sprites.size();h++)
        { sprite = sprites.get(h);
          if (!statoOld.equals(stato))
              {
               statoOld = stato;
               cambiaAnimazione(stato);
               break;
              }
      	  if (orientation.equals("n/")) {this.setIcon(sprite[0]);}
          else{if (orientation.equals("ne/")) {this.setIcon(sprite[1]);}
          else{if (orientation.equals("e/")) {this.setIcon(sprite[2]);}
          else{if (orientation.equals("se/")) {this.setIcon(sprite[3]);}
          else{if (orientation.equals("s/")) {this.setIcon(sprite[4]);}
          else{if (orientation.equals("sw/")) {this.setIcon(sprite[5]);}
          else{if (orientation.equals("w/")) {this.setIcon(sprite[6]);}
          else{if (orientation.equals("nw/")) {this.setIcon(sprite[7]);}}}}}}}}  
          try{Thread.sleep(110);}catch(Exception ex){}
        }
     
                    }

}


    
       
}
